/// SET DIRECTORY TO THE FOLDER "replication files"


////////////////////////////
//
// REGRESSION TABLES
//


** NOTE: The .csv files should be openned in Excel since some additional formatting is needed, such as columns titles as well as deleting the base category. 

use "cep84.dta", clear
** declare complex design

svyset UMP [pweight=PONDERADOR], strata(strata_cep) vce(linearized) singleunit(certainty)



///////////////////////////////
//
//  TABLE 1: SOCIOECONOMIC AND POLITICAL CHARACTERIZATION



* Identification along the left-right scale

** Does not identify


svy jackknife : regress noid i.sexo c.edad  i.educ i.tipo
est sto noid

** Identifies with the left


svy jackknife : regress left i.sexo c.edad  i.educ i.tipo
est sto left

* Incumbent support

svy jackknife : regress incumb_support i.sexo edad i.educ i.tipo

est sto incumbsupp


* Runnoff vote choice among those who voted in the runoff election

svy jackknife : regress voted_incumbent_2nd i.sexo edad i.educ i.tipo
est sto voto2da

* Interest in politics: quite or very interested


svy jackknife : regress int_pol_quite_very i.sexo c.edad i.educ i.tipo
est sto intpol



*  Participated in protests previous to the social outburst

svy jackknife : regress marcha i.sexo c.edad  i.educ i.tipo
est sto marcha

*  Voted in the last election 

svy jackknife : regress turned_out i.sexo c.edad i.educ i.tipo
est sto voted

esttab noid left incumbsupp voto2da intpol voted marcha using "tables/table_1.csv", b(%-9.3f) se(%-9.3f)  r2 nogaps label lines replace

///////////////////////////////
//
// INEQUALITY


* Identifies inequality as the most important reason behind the social upheaval

svy jackknife : regress e38_desig i.sexo c.edad i.educ i.tipo
est sto e38

* Inequality as of one the three most important problemas

svy jackknife : regress mip_desig i.sexo c.edad i.educ i.tipo
est sto mip

* Position in 1-10 equality vs rreward effort


svy jackknife : regress equality_vs_individual i.sexo c.edad  i.educ i.tipo
est sto eqvsind

* Position in 1-10 scale of government vs individual responsability

svy jackknife : regress resp_gov_vs_ind i.sexo c.edad i.educ i.tipo
est sto resp


*  EARNED VS SHOULD EARN

  svy jackknife : regress gana_ob i.sexo c.edad i.educ i.tipo
  est sto ganaob
 svy jackknife : regress should_ob i.sexo c.edad i.educ i.tipo
   est sto shouldob
   
  svy jackknife : regress gana_gte i.sexo c.edad i.educ i.tipo
    est sto ganagte
   svy jackknife : regress should_gte i.sexo c.edad i.educ i.tipo
      est sto shouldgte
	  
    svy jackknife : regress gana_doc i.sexo c.edad  i.educ i.tipo
	 est sto ganadoc
    svy jackknife : regress should_doc i.sexo c.edad  i.educ i.tipo	
	   est sto shoulddoc
  
  
* Agrees that people are rewarded by their effort
  
  svy  jackknife: regress recomp i.sexo c.edad  i.educ i.tipo
 est sto recomp
 
*  Reasons of economic success


foreach cod in "educ" "resp" "ini" "net" "padres" {
svy jackknife: regress rico_`cod' i.sexo c.edad i.educ i.tipo
est sto rico_`cod'
}


* Agrees that inequality persists because it favors the rich

svy  jackknife: regress favricos i.sexo c.edad  i.educ i.tipo
 est sto favricos


 
* Agrees that public policies reflect the majority's preferences 

svy  jackknife: regress popubciu  i.sexo c.edad i.educ i.tipo
 est sto  popubciu
 
* Agrees that public policies are close to their own preferences

svy  jackknife: regress popubown  i.sexo c.edad i.educ i.tipo
 est sto  popubown

*  Agrees that richest citizens have more influence on public policies

svy  jackknife: regress popub_ricos  i.sexo c.edad i.educ i.tipo
 est sto  popub_ricos
 
*  Trust private businesses a lot or quite

svy  jackknife: regress conf14  i.sexo c.edad i.educ i.tipo
est sto conf_emppriv


esttab e38 mip  rico_educ rico_resp rico_ini rico_net rico_padres using "tables/table_2_1.csv", b(%-9.3f) se(%-9.3f)  r2 nogaps label lines  replace


esttab  eqvsind resp ganaob shouldob ganagte shouldgte ganadoc shoulddoc  using "tables/table_2_2.csv", b(%-9.3f) se(%-9.3f)  r2 nogaps label lines  replace



esttab favricos recomp popubciu popubown popub_ricos conf_emppriv using "tables/table2_3.csv", b(%-9.3f) se(%-9.3f)  r2 nogaps label lines  replace


///////////////////////////////
//
// ATTITUDES TOWARDS DEMOCRACY

* Authoritarian index

svy  jackknife: regress auto  i.sexo c.edad i.educ i.tipo
est sto auto

* Position in 1-10 scale public and private liberties over public order


svy jackknife : regress lib i.sexo c.edad i.educ i.tipo
est sto lib

svy jackknife : regress ord i.sexo c.edad i.educ i.tipo
est sto  ord

* Democracy preferable

svy jackknife : regress dempref i.sexo c.edad i.educ i.tipo
est sto dempref

* Democracy is working bad or very bad

svy jackknife : regress evalmal i.sexo c.edad i.educ i.tipo
est sto evalmal

* Trust political parties a lot or quite

svy jackknife : regress conf4 i.sexo c.edad i.educ i.tipo
est sto confparty

* Trust Congress a lot or quite

svy jackknife : regress conf13 i.sexo c.edad i.educ i.tipo
est sto  confcong

* Trust government a lot or quite

svy jackknife : regress conf12 i.sexo c.edad i.educ i.tipo
est sto confgob


esttab auto lib ord dempref evalmal confparty confcong confgob using "tables/table_3.csv", b(%-9.3f) se(%-9.3f)  r2 nogaps label lines  replace


///////////////////////////////
//
// ATTIUDES TOWARDS USE OF FORCE

*  Justifies different actions to protest




foreach cod in "evad" "barric" "incend" "saqueo"  {
svy jackknife : regress d_`cod' i.sexo c.edad  i.educ i.tipo
est sto  d_`cod'
}

*  Justifies use of force by the police


forvalues var =1/2 {

svy jackknife : regress  d_e42_`var' i.sexo c.edad i.educ i.tipo
est sto d_e42_`var'
}

* violacion DDHH


svy jackknife : regress  violddhh i.sexo c.edad i.educ i.tipo
est sto   violddhh 

* conf carabineros


svy jackknife : regress  conf11 i.sexo c.edad  i.educ i.tipo
est sto confcarab

esttab  d_evad d_barric  d_saqueo d_incend d_e42_1 d_e42_2  violddhh confcarab using "tables/table_4_a.csv", b(%-9.3f) se(%-9.3f)  r2 nogaps label lines  


////// POLICE OR ARMED FORCED RESPONSIBLE FOR FIRES OR LOOTING

** Note: these two variables are constructed using the open question when respondents said "Other reason" to question MB_ESP39 and MB_ESP40.  These open questions are not included in the public database, but may be asked to the institutions garanteeing confidentiality. Hence, we have only included and additional dataset "cep84_resp.dta" which includes the coded answer, as well as only the variables used in the regression for replication of results.  If users want to replicated the coding, they first need to contact CEP current public opinon coordinator and request the open ended question. With the data, they may run the R script "Coding_resp.R" which will then generate the dataset used for the table of results. 

use cep84_resp.dta, clear

svyset UMP [pweight=PONDERADOR], strata(strata_cep) vce(linearized) singleunit(certainty)

* believes resp fire 

svy: regress  d39carab i.sexo c.edad  i.educ i.tipo
est sto resp_fire

* believes resp looting

svy jackknife : regress  d40carab i.sexo c.edad  i.educ i.tipo
est sto resp_loot



esttab  d_evad d_barric  d_saqueo d_incend d_e42_1 d_e42_2   resp_fire resp_loot violddhh confcarab using "tables/table_4_b.csv", b(%-9.3f) se(%-9.3f)  r2 nogaps label lines  

